var checkedBoxes = new Array();
var unCheckBoxes = new Array();
var arrLength = checkedBoxes.length;
count_A = 0.0;
count_B = 0.0;
count_C = 0.0;
count_D = 0.0;
shift_A = new Array("2","1","1","1.44");
shift_B = new Array("2.5", "1.5", "1.5", "2");
shift_C = new Array("3","3","3","3");

$().ready(function(){
	arrLength = checkedBoxes.length;	
});

function caculator(value, month, year){
	var days = daysInMonth(month, year);	
	var shiftCoefficent= parseFloat(0);		

	for(var i=1; i<=days; i++){
		i = i<10?"0"+i:i;			
		if($("#s"+i+"_1").is(":checked")){
			shiftCoefficent = parseFloat($("#s"+i+"_1").val().substr(0, $("#s"+i+"_1").val().indexOf("_")));	
			count_A += shiftCoefficent;
		}
		if($("#s"+i+"_2").is(":checked")){
			shiftCoefficent = parseFloat($("#s"+i+"_2").val().substr(0, $("#s"+i+"_2").val().indexOf("_")));
			count_B += shiftCoefficent;				
		}
		if($("#s"+i+"_3").is(":checked")){
			shiftCoefficent = parseFloat($("#s"+i+"_3").val().substr(0, $("#s"+i+"_3").val().indexOf("_")));
			count_C += shiftCoefficent;				
		}
		if($("#s"+i+"_4").is(":checked")){
			shiftCoefficent = parseFloat($("#s"+i+"_4").val().substr(0, $("#s"+i+"_4").val().indexOf("_")));
			count_D += shiftCoefficent;				
		}
	}		

	$("#shift_1_caculator").text(parseFloat(count_A));
	$("#shift_2_caculator").text(parseFloat(count_B));
	$("#shift_3_caculator").text(parseFloat(count_C));
	$("#shift_4_caculator").text(parseFloat(count_D));
	
	sumAllShiftVal();
	resetValue();
}

function resetValue(){
	count_A = 0;
	count_B = 0;
	count_C = 0;
	count_D = 0;
}

function getAllCheckedBoxes(){
	var length = $("input:checked").length;	
}

function getCheckedShiftCoefficent(){
	$("input:checked").each(function(){
		var value = $(this).attr('value');		
		var shiftCoefficent = parseFloat(value.substr(0, value.indexOf("_")));	
		var shift = value.substr(value.lastIndexOf("_")+1, 1);
//		alert("value "+value+" shiftCoeff:"+shiftCoefficent+" shift:"+shift);
		switch(parseFloat(shift)){
			case 1:
				count_A *= 1;
				count_A += shiftCoefficent;
				$("#shift_1_caculator").text(count_A);
				break;
			case 2:
				count_B *= 1;
				count_B += shiftCoefficent;
				$("#shift_2_caculator").text(count_B);
				break;
			case 3:
				count_C *= 1;
				count_C += shiftCoefficent;
				$("#shift_3_caculator").text(count_C);
				break;
			case 4:
				count_D *= 1;
				count_D += shiftCoefficent;
				$("#shift_4_caculator").text(count_D);
				break;
		}
	});	
	sumAllShiftVal();
	resetValue();	
}

function sumAllShiftVal(){
	var sum = 0;
	sum = parseFloat($("#shift_1_caculator").text()) + parseFloat($("#shift_2_caculator").text()) + parseFloat($("#shift_3_caculator").text()) + parseFloat($("#shift_4_caculator").text());
	
	$("#sumShift").text(Math.round(sum*100)/100);
	
}

function daysInMonth(month, year) {
    return new Date(year, month, 0).getDate();
}

